<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>购物满减</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-card layui-col-md12">
				<div class="layui-card-header">
					<i class="fa fa-cog"></i> 购物满减设置
				</div>
				<div class="layui-card-body" pad15>
					<div class="layui-form form-label-w8" lay-filter="">
						<div id="giveset_div">
							{php} $mjdata = json_decode($info['mjdata'],true);{/php}
							{if $mjdata}
							{foreach $mjdata as $k=>$give}
							<div class="layui-form-item">
								<label class="layui-form-label">{if $k==0}满减设置：{/if}</label>
								<div class="layui-form-mid">购物满</div>
								<div class="layui-input-inline" style="width:70px"><input type="text" name="money[]" value="{$give.money}" class="layui-input"></div>
								<div class="layui-form-mid">元，减</div>
								<div class="layui-input-inline" style="width:70px"><input type="text" name="jian[]" value="{$give.jian}" class="layui-input"></div>
								<div class="layui-form-mid">元</div>
								{if $k==0}
								<button type="button" class="layui-btn layui-btn-primary" onclick="adddata()">新增</button>
								{else}
								<button type="button" class="layui-btn layui-btn-primary" onclick="deldata(this)">删除</button>
								{/if}
							</div>
							{/foreach}
							{else}
							<div class="layui-form-item">
								<label class="layui-form-label">满减设置：</label>
								<div class="layui-form-mid">购物满</div>
								<div class="layui-input-inline" style="width:70px"><input type="text" name="money[]" value="" class="layui-input"></div>
								<div class="layui-form-mid">元，减</div>
								<div class="layui-input-inline" style="width:70px"><input type="text" name="jian[]" value="" class="layui-input"></div>
								<div class="layui-form-mid">元</div>
								<button type="button" class="layui-btn layui-btn-primary" onclick="adddata()">新增</button>
							</div>
							{/if}
						</div>
						<script>
						function adddata(){
							var html = '';
							html+='<div class="layui-form-item">';
							html+='	<label class="layui-form-label"></label>';
							html+='	<div class="layui-form-mid">购物满</div>';
							html+='	<div class="layui-input-inline" style="width:70px"><input type="text" name="money[]" value="" class="layui-input"></div>';
							html+='	<div class="layui-form-mid">元，减</div>';
							html+='	<div class="layui-input-inline" style="width:70px"><input type="text" name="jian[]" value="" class="layui-input"></div>';
							html+='	<div class="layui-form-mid">元</div>';
							html+='	<button type="button" class="layui-btn layui-btn-primary" onclick="deldata(this)">删除</button>';
							html+='</div>';
							$('#giveset_div').append(html);
						}
						function deldata(obj){
							$(obj).parent().remove();
						}
						</script>
						<div class="layui-form-item">
                            <label class="layui-form-label" >选择商品 ：</label>
                            <div class="layui-input-inline" style="width:500px">
                                <input type="radio" name="info[fwtype]" value="0" {if $info['fwtype']==0}checked{/if} title="所有商品" lay-filter="fwtype"/>
                                <input type="radio" name="info[fwtype]" value="1" {if $info['fwtype']==1}checked{/if} title="指定类目" lay-filter="fwtype"/>
                                <input type="radio" name="info[fwtype]" value="2" {if $info['fwtype']==2}checked{/if} title="指定商品" lay-filter="fwtype"/>
                            </div>
                            <div class="layui-form-mid layui-word-aux" style="margin-left:10px;">只在商城使用</div>
                            <div class="fwtype1" style="clear:both;{if $info['fwtype']!=1}display:none{/if}">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-inline" style="width:auto">
                                    <table id="setcategorydiv"  class="layui-table" style="width:500px">
                                        <thead>
                                        <tr>
                                            <th>分类ID</th>
                                            <th>分类名称</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        {if $categorydata}
                                        {foreach $categorydata as $k=>$ff}
                                        <tr class="categorylisttr"><td>{$ff.id}</td><td>{$ff.name}</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delCategory(this,{$ff.id})">删除</button></td></tr>
                                        {/foreach}
                                        {/if}
                                        <tr id="categoryaddtr">
                                            <td colspan="3"><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="showChooseCategory()">添加</button></td>
                                        </tr>
                                    </table>
                                    <input type="hidden" name="info[categoryids]" value="{$info.categoryids}"/>
                                </div>
                            </div>
                            <script>
                            var chooseCategoryLayer;
                            function showChooseCategory(){
                                chooseCategoryLayer = layer.open({type:2,title:'选择商品分类',content:"{:url('ShopCategory/choosecategory')}",area:['1000px','600px'],shadeClose:true});
                            }
                            function chooseCategory(fid,fname){
                                layer.close(chooseCategoryLayer);
                                var categoryids = [];
                                var isadd = 0;
                                $('.categorylisttr').each(function(){
                                    var thisfid = $(this).find('td:eq(0)').html();
                                    if(thisfid == fid){
                                        isadd = 1
                                        dialog('该分类已添加过了');
                                    }
                                    categoryids.push(thisfid)
                                })
                                if(isadd == 0){
                                    categoryids.push(fid)
                                    $("input[name='info[categoryids]']").val(categoryids.join(','));
                                    $('#categoryaddtr').before('<tr class="categorylisttr"><td>'+fid+'</td><td>'+fname+'</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delCategory(this,'+fid+')">删除</button></td></tr>');
                                }
                                console.log(categoryids)
                            }
                            function delCategory(obj,fid){
                                $(obj).parent().parent().remove();
                                var categoryids = [];
                                $('.categorylisttr').each(function(){
                                    categoryids.push($(this).find('td:eq(0)').html())
                                })
                                $("input[name='info[categoryids]']").val(categoryids.join(','));
                            }
                            </script>
                            <div class="fwtype2" style="clear:both;{if $info['fwtype']!=2}display:none{/if}">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-inline" style="width:auto">
                                    <table id="setproductdiv"  class="layui-table" style="width:700px">
                                        <thead>
                                        <tr>
                                            <th>商品ID</th>
                                            <th>商品名称</th>

                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        {if $productdata}
                                        {foreach $productdata as $k=>$ff}
                                        <tr class="productlisttr">
                                            <td>{$ff.id}</td>
                                            <td>{$ff.name}</td>
                                            <td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delProduct(this,{$ff.id})">删除</button></td>
                                        </tr>
                                        {/foreach}
                                        {/if}
                                        <tr id="productaddtr">
                                            <td colspan="3"><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="showChooseProduct()">添加</button></td>
                                        </tr>
                                    </table>
                                    <input type="hidden" name="info[productids]" value="{$info.productids}"/>
                                </div>
                            </div>
                            <script>
                            var cxtype = '{$info.type}';
                            var chooseProductLayer;
                            function showChooseProduct(){
                                chooseProductLayer = layer.open({type:2,title:'选择商品',content:"{:url('ShopProduct/chooseproduct')}/hidebid/1",area:['1000px','600px'],shadeClose:true});
                            }
                            function choosepro(res){
                                var product = res.product
                                layer.close(chooseProductLayer);
                                var productids = [];
                                var isadd = 0;
                                $('.productlisttr').each(function(){
                                    var thisfid = $(this).find('td:eq(0)').html();
                                    if(thisfid == product.id){
                                        isadd = 1
                                        dialog('该商品已添加过了');
                                    }
                                    productids.push(thisfid)
                                })
                                if(isadd == 0){
                                    productids.push(product.id)
                                    $("input[name='info[productids]']").val(productids.join(','));
                                    $('#productaddtr').before('<tr class="productlisttr"><td>'+product.id+'</td><td>'+product.name+'</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delProduct(this,'+product.id+')">删除</button></td></tr>');
                                }
                                console.log(productids)
                            }
                            function delProduct(obj,fid){
                                $(obj).parent().parent().remove();
                                var productids = [];
                                $('.productlisttr').each(function(){
                                    productids.push($(this).find('td:eq(0)').html())
                                })
                                $("input[name='info[productids]']").val(productids.join(','));
                            }
                            </script>
                        </div>
                        <div class="layui-form-item">
							<label class="layui-form-label" >累计消费额满减：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[total_status]" value="1" title="开启" {if $info['total_status']==1}checked{/if}>
								<input type="radio" name="info[total_status]" value="0" title="关闭" {if !$info['id'] || $info['total_status']==0}checked{/if}>
							</div>
                            <div class="layui-form-mid layui-word-aux" style="margin-left:10px;">只在商城使用，开启后，用户所有已完成的商城订单金额都计入累计消费额</div>
						</div>
                        {if getcustom('plug_tengrui')}
                        <div class="layui-form-item">
                            <label class="layui-form-label">认证{:t('会员')}：</label>
                            <div class="layui-input-inline">
                                <input type="radio" name="info[is_rzh]" value="0" {if !$info['id'] || $info['is_rzh']==0}checked{/if} title="否"/>
                                <input type="radio" name="info[is_rzh]" value="1" {if $info['id'] && $info['is_rzh']==1}checked{/if} title="是"/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">{:t('会员')}关系：</label>
                            <div class="layui-input-inline" style="width:500px">
                            <input type="radio" name="info[relation_type]" value="-1" {if !$info['id'] || $info['relation_type']==-1}checked{/if} title="所有"/>
                                <input type="radio" name="info[relation_type]" value="0" {if $info['id'] && $info['relation_type']==0}checked{/if} title="业主"/>
                                <input type="radio" name="info[relation_type]" value="1" {if $info['id'] && $info['relation_type']==1}checked{/if} title="家属"/>
                                <input type="radio" name="info[relation_type]" value="2" {if $info['id'] && $info['relation_type']==2}checked{/if} title="租户"/>
                                <input type="radio" name="info[relation_type]" value="3" {if $info['id'] && $info['relation_type']==3}checked{/if} title="买断"/>
                                <input type="radio" name="info[relation_type]" value="4" {if $info['id'] && $info['relation_type']==4}checked{/if} title="租用"/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">一户仅限一次：</label>
                            <div class="layui-input-inline">
                                <input type="radio" name="info[house_status]" value="0" {if $info['id'] && $info['house_status']==0}checked{/if} title="否"/>
                                <input type="radio" name="info[house_status]" value="1" {if !$info['id'] || $info['house_status']==1}checked{/if} title="是"/>
                            </div>
                            <div class="layui-form-mid layui-word-aux" style="margin-left:10px;">需是认证用户，且同一个小区的同一户只限一人购买，即一户仅限一次</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">授权小区：</label>
                            <div class="layui-input-inline" style="width:500px">
                                <input type="radio" name="info[group_status]" value="0" {if $info['group_status']==0}checked{/if} title="关闭" lay-filter="group_status"/>
                                <input type="radio" name="info[group_status]" value="1" {if $info['group_status']==1}checked{/if} title="开启" lay-filter="group_status"/>
                            </div>
                            <div class="group_status1 fwtypeExtend" style="clear:both;{if $info['group_status']!=1}display:none{/if}">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-inline" style="width:auto">
                                    <table id="setgroupdiv"  class="layui-table" style="width:500px">
                                        <thead>
                                        <tr>
                                            <th>小区ID</th>
                                            <th>小区名称</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        {if $groupdata}
                                        {foreach $groupdata as $gk=>$gv}
                                        <tr class="grouplisttr"><td>{$gv.id}</td><td>{$gv.fullName}</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delGroup(this,{$gv.id})">删除</button></td></tr>
                                        {/foreach}
                                        {/if}
                                        <tr id="groupaddtr">
                                            <td colspan="3"><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="showChooseGroup()">添加</button></td>
                                        </tr>
                                    </table>
                                    <input type="hidden" name="info[group_ids]" value="{$info.group_ids}"/>
                                </div>
                            </div>
                            <script>
                            var chooseGroupLayer;
                            function showChooseGroup(){
                                chooseGroupLayer = layer.open({type:2,title:'选择分组',content:"{:url('MemberTrGroup/choosegroup')}",area:['1000px','600px'],shadeClose:true});
                            }
                            function chooseGroup(fid,fname){
                                layer.close(chooseGroupLayer);
                                var group_ids = [];
                                var isadd = 0;
                                $('.grouplisttr').each(function(){
                                    var thisfid = $(this).find('td:eq(0)').html();
                                    if(thisfid == fid){
                                        isadd = 1
                                        dialog('该分组已添加过了');
                                    }
                                    group_ids.push(thisfid)
                                })
                                if(isadd == 0){
                                    group_ids.push(fid)
                                    $("input[name='info[group_ids]']").val(group_ids.join(','));
                                    $('#groupaddtr').before('<tr class="grouplisttr"><td>'+fid+'</td><td>'+fname+'</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delGroup(this,'+fid+')">删除</button></td></tr>');
                                }
                                console.log(group_ids)
                            }
                            function delGroup(obj,fid){
                                $(obj).parent().parent().remove();
                                var group_ids = [];
                                $('.grouplisttr').each(function(){
                                    group_ids.push($(this).find('td:eq(0)').html())
                                })
                                $("input[name='info[group_ids]']").val(group_ids.join(','));
                            }
                            </script>
                        </div>
                        {/if}
						<div class="layui-form-item">
							<label class="layui-form-label">状态：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[status]" value="1" title="开启" {if !$info['id'] || $info['status']==1}checked{/if}>
								<input type="radio" name="info[status]" value="0" title="关闭" {if $info['status']==0}checked{/if}>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"></label>
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit lay-filter="formsubmit">提 交</button>
							</div>
						</div>
					</div>
				</div>
			</div>
    </div>
  </div>
	{include file="public/js"/}

	<script>
    layui.form.on('radio(group_status)',function(data){
        if(data.value == 1){
            $('.group_status1').show();
        }else{
            $('.group_status1').hide();
        }
        
    })
	layui.form.on('radio(fwtype)',function(data){
		var k = data.elem.dataset.k;
        if(data.value==1){
            $('.fwtype1').show();
            $('.fwtype2').hide();
        }else if(data.value==2){
            $('.fwtype1').hide();
            $('.fwtype2').show();
        }else{

            $('.fwtype1').hide();
            $('.fwtype2').hide();
        }
        layui.form.render();
    })

	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		var index = layer.load();
		$.post('',field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status==1){
				setTimeout(function(){
					location.href = location.href
				},1000)
			}
		})
	})
  </script>
	{include file="public/copyright"/}
</body>
</html>